#!/bin/sh


##==============================================================================
##
## Extract leading arguments into $arg1 ... $arg9
## Extract options int $opts
##
##==============================================================================

n="1"
argc="0"

for i
do

    # Break on the first argument that starts with '-'
    case $i in
        -h|--help)
            help=1
            break;
            ;;
        -*)
            break;
            ;;
    esac

    # Set arguments arg1 ... arg9
    case $n in
        1)
            arg1="$i"
            shift
            ;;
        2)
            arg2="$i"
            shift
            ;;
        3)
            arg3="$i"
            shift
            ;;
        4)
            arg4="$i"
            shift
            ;;
        5)
            arg5="$i"
            shift
            ;;
        6)
            arg6="$i"
            shift
            ;;
        7)
          arg7="$i"
          shift
          ;;
        8)
            arg8="$i"
            shift
            ;;
        9)
            arg9="$i"
            shift
            ;;
    esac

    argc=`expr $argc + 1`
    n=`expr $n + 1`

done

opts=$*

#echo "help=$help"
#echo "argc=$argc"
#echo "arg1=$arg1"
#echo "arg2=$arg2"
#echo "arg3=$arg3"
#echo "arg4=$arg4"
#echo "arg5=$arg5"
#echo "arg6=$arg6"
#echo "arg7=$arg7"
#echo "arg8=$arg8"
#echo "arg9=$arg9"
#echo "opts{$opts}"

##==============================================================================
##
## Extract the --target=TARGET option up front (leave other options in 
## localopts).
##
##==============================================================================

localopts=

for opt in $opts
do
    arg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
    case $opt in
        --target=*)
            target=$arg
            ;;
        *)
            if [ -z "$localopts" ]; then
                localopts="$opt"
            else
                localopts="$localopts $opt"
            fi
            ;;
    esac
done

opts=$localopts

##==============================================================================
##
## Print the help message
##
##==============================================================================

if [ "$help" = "1" ]; then

    cat<<EOF
Usage: $0 [COMMAND] [ARGUMENTS] [OPTIONS]

COMMANDS:
    platform
        Print the platform ID for this platform.
    os
        Print operating system ID for this platform.
    hostname
        Print short hostname.
    longhostname
        Print long hostname.
    username
        Print the username of the current user.
    arch
        Print architecture ID for this platform.
    compiler
        Print compiler ID for this platform.
    cc                  
        Print command name of C compiler.
    cxx                 
        Print command name of C++ compiler.
    ar
        Print command name of archive command.
    size 
        Print command name of size command.
    cflags [--debug --pic --errwarn --pal]
        Print C compiler flags.
    cxxflags [--debug --pic --errwarn]
        Print C++ compiler flags.
    cshlibflags [--libpath=PATH --pal]
        Print compiler flags used to create a C shared library.
    cxxshlibflags [--libpath=PATH]
        Print compiler flags used to create a C++ shared library.
    cprogflags [--libpath=PATH]
        Print compiler flags used to create a C program.
    cxxprogflags [--libpath=PATH]
        Print compiler flags used to create a C++ program.
    mkdep
        Print out command to build dependencies.
    syslibs
        Print a list of system libraries.
    exports FILENAME
        Print the flags associated with controlled exports from a shared library
    libpath
        Print dynamic library path option.
    shlibname BASENAME
        Print the shared library name of the given basename.
    shlibext
        Print the shared library extension (e.g., 'so').
    openssllibdir
        Print the directory containing the OpenSSL library
    ldlibrarypath
        Print the name of the dynamic library path variable, usually LD_LIBRARY_PATH or SHLIB_PATH
    ntlm
        1 if ntlm gss spnego is available on the platform. 0 otherwise
    gssapi_ext
        1 if gssapi extensions header is available on the platform. 0 otherwise
EOF
    exit 0
fi

##==============================================================================
##
## Check arguments
##
##==============================================================================

if [ "$argc" = "0" ]; then
    echo "Usage: $0 [COMMAND] [ARGUMENTS] [OPTIONS]"
    echo "Try --help for help"
    exit 1
fi

##==============================================================================
##
## Get the platform ID and reject unknown platforms:
##
##==============================================================================

if [ -z "$target" ]; then

    __m=`uname -m 2>/dev/null` || __m=unknown
    __s=`uname -s 2>/dev/null`  || __s=unknown
    __r=`uname -r 2>/dev/null` || __r=unknown
    __v=`uname -v 2>/dev/null` || __v=unknown

    distro=
    distro_version=
    case "$__m:$__s:$__r:$__v" in
        i686:Linux:*:*)
            os=LINUX
            arch=IX86
            compiler=GNU
            distro=`lsb_release -i | awk -F":" '{ print $2 }'`
            distro_version=`lsb_release -r | awk -F":" '{ print $2 }'`
            ;;
        x86_64:Linux:*:*)
            os=LINUX
            arch=X86_64
            compiler=GNU
            distro=`lsb_release -i | awk -F":" '{ print $2 }'`
            distro_version=`lsb_release -r | awk -F":" '{ print $2 }'`
            ;;
        sun4*:SunOS:*:*)
            os=SUNOS
            arch=SPARC
            compiler=SUNPRO
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        i86pc:SunOS:*:*)
            os=SUNOS
            arch=I86PC
            compiler=SUNPRO
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        *:AIX:*:*)
            os=AIX
            arch=PPC
            compiler=IBM
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        ia64:HP-UX:*:*)
            os=HPUX
            arch=IA64
            compiler=HP
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        9000/800:HP-UX:*:*)
            os=HPUX
            arch=PARISC
            compiler=HP
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        i386:Darwin:*:Darwin* | x86_64:Darwin:*:Darwin*)
            os=DARWIN
            arch=IX86
            compiler=GNU
            distro=`uname -s`
            distro_version=`uname -v`
            ;;
        ppc*:Linux:*)
            os=LINUX
            arch=PPC
            compiler=GNU
            distro=`lsb_release -i | awk -F":" '{ print $2 }'`
            distro_version=`lsb_release -r | awk -F":" '{ print $2 }'`
	    ;;
        arm*:Linux:*)
            os=LINUX
            arch=ARM
            compiler=GNU
            distro=`lsb_release -i | awk -F":" '{ print $2 }'`
            distro_version=`lsb_release -r | awk -F":" '{ print $2 }'`
	    ;;
        *)
            echo "$0: error: unsupported platform: $__m:$__s:$__r:$__v"
            exit 1
            ;;
    esac
    platform=$os"_"$arch"_"$compiler
else
    platform=$target
fi

case "$platform" in

    LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
        compiler_version=`gcc --version | awk -F" " 'match($0, /[0-9]*\.[0-9]*\.[0-9]*/){ if (match($0,  /[0-9]*\.[0-9]*\.[0-9]*/, m)) print m[0] }'`
        compiler_major_version=`echo $compiler_version | awk -F'.' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'.' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'.' '{ print $3}'`
        ;;
    MONTAVISTA_IX86_GNU)
        compiler_version=`586-gcc --version | awk -F" " 'match($0, /[0-9]*\.[0-9]*\.[0-9]*/){ if (match($0,  /[0-9]*\.[0-9]*\.[0-9]*/, m)) print m[0] }'`
        compiler_major_version=`echo $compiler_version | awk -F'.' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'.' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'.' '{ print $3}'`
        ;;
    NETBSD_IX86_GNU)
        compiler_version=`netbsd-gcc --version | awk -F" " 'match($0, /[0-9]*\.[0-9]*\.[0-9]*/){ if (match($0,  /[0-9]*\.[0-9]*\.[0-9]*/, m)) print m[0] }'`
        compiler_major_version=`echo $compiler_version | awk -F'.' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'.' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'.' '{ print $3}'`
        ;;
    SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
        compiler_version=`cc -V 2>&1  |  awk -F":" '{ print $2 }'  |  sed "s/.*${command} \([^ ]*\).*$/\1/"` 
        compiler_major_version=`echo $compiler_version | awk -F'/' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'/' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'/' '{ print $3}'`
        ;;
    AIX_PPC_IBM)
        compiler_version=`xlc_r -qversion | awk -F":" '/Version/ { print $2 }'`
        compiler_major_version=`echo $compiler_version | awk -F'/' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'/' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'/' '{ print $4}'`
        ;;
    HPUX_IA64_HP|HPUX_PARISC_HP)
        compiler_version=`aCC -V 2>&1`
        compiler_major_version=`echo $compiler_version | awk -F' ' '{ print $4}'`
        compiler_minor_version=`echo $compiler_version | awk -F' ' '{ print $5}' | awk -F"." '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F' ' '{ print $5}' | awk -F"." '{ print $3}'`
        ;;
    DARWIN_IX86_GNU)
        compiler_version=`clang --version | awk -F" " 'match($0, /version [0-9]*\.[0-9]*\.[0-9]*/){ print $4 }'`
        compiler_major_version=`echo $compiler_version | awk -F'.' '{ print $1}'`
        compiler_minor_version=`echo $compiler_version | awk -F'.' '{ print $2}'`
        compiler_revision=`echo $compiler_version | awk -F'.' '{ print $3}'`
        ;;
    *)
        echo "$0: error: unsupported platform: $platform"
        exit 1
        ;;
esac

##==============================================================================
##
## platform command:
##
##==============================================================================

if [ "$arg1" = "platform" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    echo $platform
    exit
fi

##==============================================================================
##
## os command:
##
##==============================================================================

if [ "$arg1" = "os" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        MONTAVISTA*)
            os=LINUX
            ;;
        NETBSD*)
            os=BSD
            ;;
    esac

    echo $os
    exit
fi

##==============================================================================
##
## hostname command:
##
##==============================================================================

if [ "$arg1" = "hostname" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    if [ "$os" = "DARWIN" ] ; then 
        hostname -s
    else
        hostname
    fi
    exit
fi

##==============================================================================
##
## longhostname command:
##
##==============================================================================

if [ "$arg1" = "longhostname" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in

        LINUX*)
            ##
            ## First try hostname -f (this will fail on some Linux systems)
            ##
            hn=`hostname -f 2> /dev/null`
            if [ "$?" = "0" ]; then
                echo $hn
            else
                hostname
            fi
            ;;
        MONTAVISTA*)
            hostname
            ;;
        NETBSD*)
            hostname
            ;;
        DARWIN*)
            hostname
            ;;
        *)
	    ##
	    ## Attempt to obtain domain name from /etc/resolve.conf
	    ##
            if [ -f "/etc/resolv.conf" ]; then
              domain=`cat /etc/resolv.conf | grep '^domain' | awk '{print $2}'`

              if [ -n "$domain" ]; then
                echo `hostname`.$domain
                exit 0
              fi
            fi

	    ##
	    ## Attempt to obtain long hostname with 'nslookup' command
	    ##
            if [ -n "`which nslookup`" ]; then
		host=`hostname`
		lhs=`nslookup $host | grep '^Name:' | awk '{print $2}' | grep $host`
		if [ -n "$lhs" ]; then
		    echo $lhs
		    exit 0
		fi
	    fi

	    ##
	    ## Just print host hostname:
	    ##
            hostname
            ;;
    esac

    exit
fi

##==============================================================================
##
## username command:
##
##==============================================================================

if [ "$arg1" = "username" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in

        *)
            id | cut -f2 -d'(' | cut -f1 -d')'
            ;;
    esac

    exit
fi

##==============================================================================
##
## arch command:
##
##==============================================================================

if [ "$arg1" = "arch" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        MONTAVISTA*)
            arch=IX86
            ;;
        NETBSD*)
            arch=IX86
            ;;
    esac

    echo $arch
    exit
fi

##==============================================================================
##
## compiler command:
##
##==============================================================================

if [ "$arg1" = "compiler" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        MONTAVISTA*)
            compiler=GNU
            ;;
        NETBSD*)
            compiler=GNU
            ;;
    esac

    echo $compiler
    exit
fi

##==============================================================================
##
## cc command:
##
##==============================================================================

if [ "$arg1" = "cc" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in

        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            echo gcc
            ;;
        MONTAVISTA_IX86_GNU)
            echo 586-gcc
            ;;
        NETBSD_IX86_GNU)
            echo netbsd-gcc
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            echo cc
            ;;
        AIX_PPC_IBM)
            echo xlc_r
            ;;
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo aCC -Ae
            ;;
        DARWIN_IX86_GNU)
            echo clang
            ;;
    esac

    exit
fi

##==============================================================================
##
## cxx command:
##
##==============================================================================

if [ "$arg1" = "cxx" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            echo g++
            ;;
        MONTAVISTA_IX86_GNU)
            echo 586-g++
            ;;
        NETBSD_IX86_GNU)
            echo netbsd-g++
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            echo CC
            ;;
        AIX_PPC_IBM)
            echo xlC_r 
            ;;
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo aCC -AA
            ;;
        DARWIN_IX86_GNU)
            echo clang++
            ;;
    esac

    exit
fi

##==============================================================================
##
## ar command:
##
##==============================================================================

if [ "$arg1" = "ar" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in

        MONTAVISTA_IX86_GNU)
            echo 586-ar
            ;;
        NETBSD_IX86_GNU)
            echo netbsd-ar
            ;;
        *)
            echo ar
            ;;
    esac

    exit
fi

##==============================================================================
##
## size command:
##
##==============================================================================

if [ "$arg1" = "size" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in

        LINUX_IX86_GNU|LINUX_X86_64_GNU)
            echo size
            ;;
        LINUX_ARM_GNU)
            echo size
            ;;
        MONTAVISTA_IX86_GNU)
            echo size
            ;;
        NETBSD_IX86_GNU)
            echo size
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)

            # the size utiltiy is not available on solaris unless you install gnu binutils
            # separately

            echo "echo \'size not avaliable\'"
            ;;
        AIX_PPC_IBM|LINUX_PPC_GNU)
            echo size
            ;;
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo size
            ;;
        DARWIN_IX86_GNU)
            echo size
            ;;
	*)
	    echo "echo \'Unsuported platform: $platform\'"
	    exit 1
	    ;;
    esac

    exit
fi

##==============================================================================
##
## 'cflags' command:
## 'cxxflags' command:
##
##==============================================================================

if [ "$arg1" = "cflags" -o "$arg1" = "cxxflags" ]; then

    if [ "$argc" != "1" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    if [ "$arg1" = "cflags" ]; then
        c_opt=1
    else
        cxx_opt=1
    fi

    for opt in $opts
    do
        case $opt in
            --debug)
                debug_opt=1
                ;;
            --gcov)
                gcov_opt=1
                ;;
            --pic)
                pic_opt=1
                ;;
            --errwarn)
                errwarn_opt=1
                ;;
            --size)
                size_opt=1
                ;;
            --pal)
                pal_opt=1
                ;;
            *)
                echo "$arg1: unknown option: $opt"
                exit 1
                ;;
        esac
    done

    r=""

    ## Always build with debug symbols
    r="$r -g"

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|MONTAVISTA_IX86_GNU|NETBSD_IX86_GNU|LINUX_ARM_GNU)
            if test $cxx_opt ; then
                r="$r -std=gnu++98"
            fi    

            if test -z "$debug_opt"; then
                if test -n "$size_opt"; then
                    r="$r -Os"
                else
                    r="$r -O2"
                fi
            fi

            test -n "$gcov_opt" && r="$r -ftest-coverage -fprofile-arcs"
            test -n "$pic_opt" && r="$r -fPIC"
            test -n "$errwarn_opt" && r="$r -Werror"
            r="$r -Wall"
            r="$r -fvisibility=hidden"
            r="$r -fno-strict-aliasing"
            r="$r -fstack-protector-all"
            r="$r -D_GNU_SOURCE"
            r="$r -D_XOPEN_SOURCE=600"
            r="$r -DGSS_USE_IOV=1"

	        # _BSD_SOURCE is deprecated on PPC and gcc 6 and later

            if test "$platform" = "LINUX_PPC_GNU" ; then
		        r="$r -D_DEFAULT_SOURCE"
	        else
                if test "$os" = "LINUX" ; then
                    if test $compiler_major_version -gt "5"; then
                        r="$r -D_DEFAULT_SOURCE"
                    else
                        r="$r -D_BSD_SOURCE"
                    fi
                else
                    r="$r -D_DEFAULT_SOURCE"
                fi
            fi
            #test -n "$cxx_opt" && r="$r -fno-exceptions"
            #test -n "$cxx_opt" && r="$r -fno-enforce-eh-specs"
            #test -n "$cxx_opt" && r="$r -fno-rtti"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            ## Optimization options.
            if test -z "$debug_opt"; then
                test -n "$c_opt" && r="$r"
                test -n "$cxx_opt" && r="$r -O"
            fi

            ## Generate position independent code (PIC).
            test -n "$pic_opt" && r="$r -KPIC"

            ## treat warnings as errors.
            test -n "$errwarn_opt" && r="$r -errwarn"

            ## multi-threaded support.
            r="$r -mt"

            ## avoid optimizations that increase object code size.
            r="$r -xspace"

            ## specify target system.
            r="$r -xtarget=generic"

            ## specify target architecture.
            r="$r -xarch=generic"

            ## hide all library symbols by default.            
            r="$r -xldscope=hidden"

            ## Stack overflow checking
            r="$r -xcheck=%all"

            ## display brief message tag for each warning message.
            r="$r -errtags=yes"

            ## use standar pthread funciton declarations
            r="$r -D_POSIX_PTHREAD_SEMANTICS"

            r="$r -D_XOPEN_SOURCE=500"

            r="$r -D__EXTENSIONS__"

            r="$r -I/usr/include/kerberosv5"
            ## suppress all warning messages.
            #r="$r -erroff=%all"

            ## suppress this warning message.
            test -n "$c_opt" && r="$r -erroff=E_WHITE_SPACE_IN_DIRECTIVE"
            
            ;;
        AIX_PPC_IBM)
            test -n "$debug_opt" && r="$r -qcheck"
            test -z "$debug_opt" && r="$r -O2"
            test -n "$pic_opt" && r="$r -qpic"
            ## treat warnings as errors.
            test -n "$errwarn_opt" && r="$r -qhalt=w"
            r="$r -q64"
            r="$r -Daix"

            ## Stack options for AIX.
            ## Not supported for 6.1, is for 7.1
            ## r="$r -qstackprotect=all"
            ;;
        HPUX_IA64_HP)
            test -z "$debug_opt" && r="$r -s +O1"
            ## treat warnings as errors.
            test -n "$errwarn_opt" && r="$r +We"
            r="$r +DD64"
            r="$r -mt"
            r="$r +Z"
            r="$r -Dhpux"
            r="$r +W4232"
            r="$r +W4275"
            r="$r -D_XOPEN_SOURCE=500"
            r="$r -D__STDC_EXT__"
            ;;
        HPUX_PARISC_HP)
            ## Always build with debug symbols
            r="$r +noobjdebug"

            test -z "$debug_opt" && r="$r +O2 -s"
            ## treat warnings as errors.
            test -n "$errwarn_opt" && r="$r +We"
            r="$r +Z"
            r="$r +DAportable"
            r="$r -mt"
            r="$r -Dhpux"
            r="$r -D_PSTAT64"
            r="$r +W749"
            r="$r +W740"
            r="$r -Wl,+s"
            r="$r -D_INCLUDE__STDC_A1_SOURCE"
            r="$r -D__STDC_EXT__"
            r="$r -D_XOPEN_SOURCE_EXTENDED"
            ;;
        DARWIN_IX86_GNU)
            test -z "$debug_opt" && r="$r -O2"
            test -n "$pic_opt" && r="$r -fPIC"
            ## treat warnings as errors.
            test -n "$errwarn_opt" && r="$r -Werror"
            r="$r -Wall"
            r="$r -I/usr/local/include"
            r="$r -Dmacos"
            r="$r -fvisibility=hidden"
            r="$r -fstack-protector-all"
            r="$r -DGSS_USE_IOV=1"
            ;;
    esac

    echo $r
    exit
fi

##==============================================================================
##
## 'cshlibflags' command:
## 'cxxshlibflags' command:
##
##==============================================================================

if [ "$arg1" = "cshlibflags" -o "$arg1" = "cxxshlibflags" ]; then

    if [ "$argc" != "1" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    if [ "$arg1" = "cshlibflags" ]; then
        c_opt=1
    else
        cxx_opt=1
    fi

    for opt in $opts
    do
        arg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
        case $opt in
            --libpath=*)
                libpath_opt=$arg
                ;;
            --pal)
                palshlib_opt=1
                ;;
            *)
                echo "$arg1: unknown option: $opt"
                exit 1
                ;;
        esac
    done

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            r="$r -shared"
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        MONTAVISTA_IX86_GNU)
            r="$r -shared"
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        NETBSD_IX86_GNU)
            r="$r -shared"
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)

            ## multi-threaded support.
            r="$r -mt"

            ## ignore the LD_LIBRARY_PATH variable when linking.
            r="$r -i"

            ## Build a dynamic shared library (rather than executable file).
            r="$r -G"

            ## Generate position independent code (PIC).
            r="$r -KPIC"

            ## Link with the standard C++ library.
            test -n "$cxx_opt" && r="$r -lCstd"

            ## link time library contains 'nanosleep'
            r="$r -lrt"

            ## hide all library symbols by default.
            r="$r -xldscope=hidden"

            ## Add libpath_opt to the dynamic library path.
            test -n "$libpath_opt" && r="$r -R:$libpath_opt"

            ;;
        AIX_PPC_IBM)
            r="$r -brtl"
            r="$r -G"
            r="$r -qmkshrobj"
            r="$r -q64"
            if [ -n "$libpath_opt" ]; then
                r="$r -blibpath:$libpath_opt:/usr/lib:/lib"
            else
                r="$r -blibpath:/usr/lib:/lib"
            fi
            r="$r -bnolibpath"
            r="$r -Wl,-bnoautoexp"
            ;;
        HPUX_IA64_HP)
            r="$r +DD64"
            r="$r -mt"
            r="$r +Z -Dhpux"
            r="$r +W4232"
            r="$r +W4275" 
            r="$r -D_XOPEN_SOURCE=600"
            r="$r -D__STDC_EXT__"
            r="$r -lc"
            r="$r -lrt"
            r="$r -b"
            r="$r -Bhidden"
            test -n "$libpath_opt" && r="$r +b $libpath_opt"
            test -n "$cxx_opt" && r="$r -lstd_v2"
            test -n "$cxx_opt" && r="$r -lunwind"
            test -n "$cxx_opt" && r="$r -lCsup"
            ;;
        HPUX_PARISC_HP)
            r="$r -b"
            r="$r -lrt"
            r="$r -Bhidden"
            r="$r -Wl,+s"
            ;;
        DARWIN_IX86_GNU)
            r="$r -dynamiclib"
            r="$r -fvisibility=hidden"
            test -n "$libpath_opt" && r="$r -R$libpath_opt"
            ;;
    esac

    echo $r
    exit
fi

##==============================================================================
##
## 'cprogflags' command:
## 'cxxprogflags' command:
##
##==============================================================================

if [ "$arg1" = "cprogflags" -o "$arg1" = "cxxprogflags" ]; then

    if [ "$argc" != "1" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    if [ "$arg1" = "cprogflags" ]; then
        c_opt=1
    else
        cxx_opt=1
    fi

    for opt in $opts
    do
        arg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
        case $opt in
            --libpath=*)
                libpath_opt=$arg
                ;;
            *)
                echo "$arg1: unknown option: $opt"
                exit 1
                ;;
        esac
    done

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        MONTAVISTA_IX86_GNU)
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        NETBSD_IX86_GNU)
            test -n "$libpath_opt" && r="$r -Wl,-rpath=$libpath_opt"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)

            ## multi-threaded support.
            r="$r -mt"

            ## ignore the LD_LIBRARY_PATH variable when linking.
            r="$r -i"

            ## link time library contains 'nanosleep'
            r="$r -lrt"

            ## hide all library symbols by default.
            r="$r -xldscope=hidden"

            ## Add libpath_opt to the dynamic library path.
            test -n "$libpath_opt" && r="$r -R:$libpath_opt"

            ;;

        AIX_PPC_IBM)
            r="$r -brtl"
            r="$r -q64"
            r="$r -qcpluscmt"
            if [ -n "$libpath_opt" ]; then
                r="$r -blibpath:$libpath_opt:/usr/lib:/lib"
            else
                r="$r -blibpath:/usr/lib:/lib"
            fi
            ;;
        HPUX_IA64_HP)
            r="$r +DD64"
            r="$r -mt"
            r="$r +Z -Dhpux"
            r="$r +W4232"
            r="$r +W4275" 
            r="$r -D_XOPEN_SOURCE=600"
            r="$r -D__STDC_EXT__"
            r="$r -lrt"
            r="$r -Bhidden"
            test -n "$libpath_opt" && r="$r +b $libpath_opt"
            ;;
        HPUX_PARISC_HP)
            r="$r +Z"
            r="$r +DAportable"
            r="$r -mt"
            r="$r -lrt"
            r="$r -D_PSTAT64"
            ;;
        DARWIN_IX86_GNU)
            test -n "$libpath_opt" && r="$r -R$libpath_opt"
            ;;
    esac

    echo $r
    exit
fi

##==============================================================================
##
## mkdep command:
##
##==============================================================================

if [ "$arg1" = "mkdep" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            r="gcc -M"
            ;;
        MONTAVISTA_IX86_GNU)
            r="586-gcc -M"
            ;;
        NETBSD_IX86_GNU)
            r="gcc -M"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            r="CC -xM1"
            ;;
        AIX_PPC_IBM)
            r="xlc++_r -E -qmakedep=gcc"
            ;;
        HPUX_IA64_HP|HPUX_PARISC_HP)
            r="aCC +make -E"
            ;;
        DARWIN_IX86_GNU)
            r="gcc -M"
            ;;
    esac

    echo "$r"
    exit
fi

##==============================================================================
##
## syslibs command:
##
##==============================================================================

if [ "$arg1" = "syslibs" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            r="-lpthread -ldl -lpam"
            ;;
        MONTAVISTA_IX86_GNU)
            r="-lpthread -ldl -lpam"
            ;;
        NETBSD_IX86_GNU)
            r="-lpthread -ldl -lpam"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            r="-lpthread -lsocket -lnsl -ldl -lpam"
            ;;
        AIX_PPC_IBM)
            r="-lpthread -ldl -lpam"
            ;;
        HPUX_IA64_HP)
            r="-lpthread -ldl -lpam"
            ;;
        HPUX_PARISC_HP)
            r="-lpthread -lpam"
            ;;
        DARWIN_IX86_GNU)
            r="-lpthread -ldl -lpam"
            ;;
    esac

    echo "$r"
    exit
fi

##==============================================================================
##
## libpath command:
##
##==============================================================================

if [ "$arg1" = "libpath" ]; then

    if [ "$argc" -lt "2" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1 PATH"
        echo
        exit 1
    fi

    r=""
    args="$arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9"

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            for path in $args
            do
                r="$r -Wl,-rpath=$path"
            done
            ;;
        MONTAVISTA_IX86_GNU)
            for path in $args
            do
                r="$r -Wl,-rpath=$path"
            done
            ;;
        NETBSD_IX86_GNU)
            for path in $args
            do
                r="$r -Wl,-rpath=$path"
            done
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            for path in $args
            do
                r="$r -R:$path"
            done
            ;;
        AIX_PPC_IBM)
            r="-blibpath:/usr/lib:/lib"
            for path in $args
            do
                r="$r:$path"
            done
            ;;
        HPUX_IA64_HP)
            r="-Wl,+b,"
            first=1
            for path in $args
            do
                if [ -n "$first" ]; then
                   r="$r$path"
                   first=""
                else
                   r="$r:$path"
                fi
            done
            ;;
        HPUX_PARISC_HP)
            #r="-Wl,+cdp,"
            r="-Wl,+b,"
            first=1
            for path in $args
            do
                if [ -n "$first" ]; then
                   r="$r$path"
                   first=""
                else
                   r="$r:$path"
                fi
            done
            ;;
        DARWIN_IX86_GNU)
            for path in $args
            do
                r="$r -R$path"
            done
            ;;
    esac

    echo "$r"
    exit
fi

##==============================================================================
##
## libname command:
##
##==============================================================================

if [ "$arg1" = "libname" ]; then

    if [ "$argc" -lt "2" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1 PATH"
        echo
        exit 1
    fi

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            ;;
        MONTAVISTA_IX86_GNU)
            ;;
        NETBSD_IX86_GNU)
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            ;;
        AIX_PPC_IBM)
            ;;
        HPUX_IA64_HP)
            ;;
        HPUX_PARISC_HP)
            ;;
        DARWIN_IX86_GNU)
            r="$r -Wl,-install_name -Wl,$arg2"
            ;;
    esac

    echo "$r"
    exit
fi


##==============================================================================
##
## exports command:
##
##==============================================================================

if [ "$arg1" = "exports" ]; then

    if [ "$argc" -lt "2" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1 FILENAME"
        echo
        exit 1
    fi

    r=""

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU)
            ;;
        MONTAVISTA_IX86_GNU)
            ;;
        NETBSD_IX86_GNU)
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            ;;
        AIX_PPC_IBM)
            r="$r -Wl,-bE:$arg2"
            ;;
        HPUX_IA64_HP)
            r="$r -Bextern:$arg2"
            ;;
        HPUX_PARISC_HP)
            r="$r -Bextern:$arg2"
            ;;
        DARWIN_IX86_GNU)
            ;;
    esac

    echo "$r"
    exit
fi

##==============================================================================
##
## 'shlibname' command:
##
##==============================================================================

if [ "$arg1" = "shlibname" ]; then

    if [ "$argc" != "2" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1 LIBBASENAME"
        echo
        exit 1
    fi

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            echo "lib$arg2.so"
            ;;
        MONTAVISTA_IX86_GNU)
            echo "lib$arg2.so"
            ;;
        NETBSD_IX86_GNU)
            echo "lib$arg2.so"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            echo "lib$arg2.so"
            ;;
        AIX_PPC_IBM)
            echo "lib$arg2.so"
            ;;
        HPUX_IA64_HP)
            echo "lib$arg2.so"
            ;;
        HPUX_PARISC_HP)
            echo "lib$arg2.sl"
            ;;
        DARWIN_IX86_GNU)
            echo "lib$arg2.dylib"
            ;;
    esac

    exit
fi

##==============================================================================
##
## 'shlibext' command:
##
##==============================================================================

if [ "$arg1" = "shlibext" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
            echo "so"
            ;;
        MONTAVISTA_IX86_GNU)
            echo "so"
            ;;
        NETBSD_IX86_GNU)
            echo "so"
            ;;
        SUNOS_I86PC_SUNPRO|SUNOS_SPARC_SUNPRO)
            echo "so"
            ;;
        AIX_PPC_IBM)
            echo "so"
            ;;
        HPUX_IA64_HP)
            echo "so"
            ;;
        HPUX_PARISC_HP)
            echo "sl"
            ;;
        DARWIN_IX86_GNU)
            echo "dylib"
            ;;
        *)
            echo "so"
    esac

    exit
fi

##==============================================================================
##
## 'openssllibdir' command:
##
##==============================================================================

if [ "$arg1" = "openssllibdir" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    ##
    ## (1) Locate libdir with pkg-config.
    ##

    pkgconfig=`which pkg-config 2> /dev/null`

    if [ -x "$pkgconfig" ]; then
        libdir=`$pkgconfig --variable=libdir openssl`
    fi

    ##
    ## (2) Locate libdir relative to openssl program.
    ##

    if [ -z "$libdir" ]; then
        openssl=`which openssl 2> /dev/null`

        if [ -x "$openssl" ]; then
            case "$platform" in
                HPUX_PARISC_HP)
                    shlibext="sl"
                    ;;
                DARWIN_IX86_GNU)
                    shlibext="dylib"
                    ;;
                *)
                    shlibext="so"
                    ;;
            esac
            dirname=`dirname $openssl`/..
            if [ -d "$dirname" ]; then
                dirname=`cd "$dirname"; pwd`
                if [ -f "$dirname/lib/libssl.$shlibext" ]; then
                    libdir=$dirname/lib
                elif [ -f "$dirname/ssl/lib/libssl.$shlibext" ]; then
                    libdir=$dirname/ssl/lib
                fi
            fi
        fi
    fi

    ##
    ## (3) Locate libdir based on platform identifier.
    ##

    if [ -z "$libdir" ]; then
        case "$platform" in
            LINUX_IX86_GNU|LINUX_X86_64_GNU|LINUX_PPC_GNU|LINUX_ARM_GNU)
                if [ -f "/usr/lib/libssl.so" ]; then
                    libdir=/usr/lib
                fi
                ;;
            SUNOS_I86PC_SUNPRO)
                if [ -f "/usr/sfw/lib/libssl.so" ]; then
                    libdir=/usr/sfw/lib
                fi
                ;;
            SUNOS_SPARC_SUNPRO)
                if [ -f "/usr/local/ssl/lib/libssl.so" ]; then
                    libdir=/usr/local/ssl/lib
                fi
                ;;
            AIX_PPC_IBM)
                if [ -f "/usr/lib/libssl.sl" ]; then
                    libdir=/usr/lib
                fi
                ;;
            HPUX_IA64_HP)
                if [ -f "/opt/openssl/lib/libssl.sl" ]; then
                    libdir=/opt/openssl/lib
                fi
                ;;
            HPUX_PARISC_HP)
                if [ -f "/usr/local/lib/libssl.sl" ]; then
                    libdir=/usr/local/lib
                fi
                ;;
            DARWIN_IX86_GNU)
                if [ -f "/usr/lib/libssl.dylib" ]; then
                    libdir=/usr/lib
                fi
                ;;
            *)
                echo "so"
        esac
    fi

    echo "$libdir"
    exit

fi

##==============================================================================
##
## 'ldlibrarypath' command:
##
##==============================================================================

if [ "$arg1" = "ldlibrarypath" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo "SHLIB_PATH"
            ;;
        DARWIN_IX86_GNU)
            echo "DYLD_LIBRARY_PATH"
            ;;
        *)
            echo "LD_LIBRARY_PATH"
    esac

    exit
fi

##==============================================================================
##
## 'semnamelocalprefix' command (determine the prefix for a semaphore)
##
##==============================================================================

if [ "$arg1" = "semnamelocalprefix" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo "/tmp/"
            ;;
        *)
            echo "/"
    esac

    exit
fi

##==============================================================================
##
## 'shmnamelocalprefix' command (determine the prefix for a shmaphore)
##
##==============================================================================

if [ "$arg1" = "shmnamelocalprefix" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo "/tmp/"
            ;;
        *)
            echo "/"
    esac

    exit
fi

##==============================================================================
##
## 'semnameglobalprefix' command (determine the prefix for a semaphore)
##
##==============================================================================

if [ "$arg1" = "semnameglobalprefix" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo "/tmp/"
            ;;
        *)
            echo "/"
    esac

    exit
fi

##==============================================================================
##
## 'shmnameglobalprefix' command (determine the prefix for a shmaphore)
##
##==============================================================================

if [ "$arg1" = "shmnameglobalprefix" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP)
            echo "/tmp/"
            ;;
        *)
            echo "/"
    esac

    exit
fi

##==============================================================================
##
## 'faultinjection' command 
##     Whether fault injection is supported (1) or not (0)
##
##==============================================================================

if [ "$arg1" = "faultinjection" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$os" in
        LINUX)
            # supported!
            echo "1"
            ;;
        *)
            # not-supported!
            echo "0"
    esac

    exit
fi

##==============================================================================
##
## 'ntlm' command 
##     Whether gss negotiated ntlm is supported (1) or not (0)
##
##==============================================================================

if [ "$arg1" = "ntlm" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$os" in
        LINUX*)
            # supported!
            case "$distro" in
                *edHat*)
                    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                   
                    if [ "$distro_major_version" -gt "7" ] ; then
                       echo "1"
                    elif [ "$distro_major_version" -eq "7" ] ; then
                       if [ "$distro_minor_version" -ge "3" ] ; then
                          echo "1"
                       else
                          echo "0"
                       fi
                    else
                       echo "0"
                    fi
    
                    ;;
                *entOS*)
                    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                   
                    if [ "$distro_major_version" -gt "7" ] ; then
                       echo "1"
                    elif [ "$distro_major_version" -eq "7" ] ; then
                       if [ "$distro_minor_version" -ge "3" ] ; then
                          echo "1"
                       else
                          echo "0"
                       fi
                    else
                       echo "0"
                    fi
    
                    ;;
    
                *SUSE*)
    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                    if [ "$distro_major_version" -ge "12" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
    
                *ebian*)
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                    if [ "$distro_major_version" -ge "7" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
    
                *buntu*)
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`

                    if [ "$distro_major_version" -ge "14" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
                *)
                    # not-supported!
                    echo "0"
            esac
            ;;

        *)
            # not-supported!
            echo "0"
    esac

    exit
fi


##==============================================================================
##
## 'gssapi_ext' command 
##     Whether gss negotiated gssapi_ext is supported (1) or not (0)
##
##==============================================================================

if [ "$arg1" = "gssapi_ext" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$os" in
        LINUX*)
            # supported!
            case "$distro" in
                *edHat*)
                    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                   
                    if [ "$distro_major_version" -gt "5" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
    
                    ;;
                *entOS*)
                    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                   
                    if [ "$distro_major_version" -gt "5" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
    
                    ;;
    
                *SUSE*)
    
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                    if [ "$distro_major_version" -ge "13" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
    
                *ebian*)
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`
                    if [ "$distro_major_version" -ge "7" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
    
                *buntu*)
                    distro_major_version=`echo $distro_version | awk -F'.' '{ print $1}'`
                    distro_minor_version=`echo $distro_version | awk -F'.' '{ print $2}'`

                    if [ "$distro_major_version" -ge "14" ] ; then
                       echo "1"
                    else
                       echo "0"
                    fi
                    ;;
            SUNOS)
                    echo "1"
                    ;;
            AIX)
                    echo "1"
                    ;;
            HPUX)
                    echo "1"
                    ;;
            DARWIN)
                    echo "0"
                    ;;
                *)
                    # not-supported!
                    echo "0"
            esac
            ;;

        *)
            # not-supported!
            echo "0"
    esac

    exit
fi

##==============================================================================
##
## 'vsnprintf' command 
##     Whether vsnprintf return -1 on NULL buffer or not
##
##==============================================================================

if [ "$arg1" = "vsnprintf" ]; then

    if [ "$argc" != "1" -o "$opts" != "" ]; then
        echo "Usage: $0 $arg1"
        echo
        exit 1
    fi

    case "$platform" in
        HPUX_IA64_HP|HPUX_PARISC_HP|SUNOS_SPARC_SUNPRO)
            # vsnprintf returns -1 if buffer is NULL
            echo "1"
            ;;
        *)
            # vsnprintf returns number of characters that would have been written
            # if buffer is big enough
            echo "0"
    esac

    exit
fi

##==============================================================================
##
## Unknown command:
##
##==============================================================================

echo "$0: unknown command: $arg1"
exit 1
